
package com.kingdee.signup.api;

import android.content.Context;
import com.google.gson.Gson;
import com.kingdee.signup.common.Constants;
import com.kingdee.signup.model.*;
import com.kingdee.signup.utils.*;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

// Referenced classes of package com.kingdee.signup.api:
//            BaseAPI

public class LoginAPI extends BaseAPI {

	public LoginAPI(Context context, boolean flag) {
		super(context, flag);
		appConsumerKey = "66e7158e-28fb-498d-b7cc-1c9bbbcf3fe4";
		appConsumerSecret = "ca0f095af3b88622db09d2cf13373579";
		mContext = context;
	}

	public static String MD5(String s)
    {
		String s1="";
        MessageDigest messagedigest;
		try {
			messagedigest = MessageDigest.getInstance("MD5");
			  char ac[];
		        byte abyte0[];
		        ac = s.toCharArray();
		        abyte0 = new byte[ac.length];
		        for(int i=0;i<ac.length;i++){
		        	abyte0[i] = (byte)ac[i];
		        }
		         
		        byte abyte1[];
		        StringBuffer stringbuffer;
		        abyte1 = messagedigest.digest(abyte0);
		        stringbuffer = new StringBuffer();
		        for(int j=0;j<abyte1.length;j++){
		            int k = 255 & abyte1[j];
		            if(k < 16){
		                stringbuffer.append("0");
		            }
		            stringbuffer.append(Integer.toHexString(k));
		        }
		        s1 = stringbuffer.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return s1;

    }

	public String getHash(String s, String s1) {
		SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
		Object aobj[] = new Object[3];
		aobj[0] = appConsumerSecret;
		aobj[1] = simpledateformat.format(new Date());
		aobj[2] = s1;
		return MD5(String.format("%s%s%s", aobj));
	}

	public LoginResult getLoginData(String s, String s1, String s2, String s3,
			String s4, String s5, String s6) throws Exception {
		//初始化
		CommonUtils.addConfigInfo(mContext, "Lat", "24.87");
		CommonUtils.addConfigInfo(mContext, "Lon","118.67");
		CommonUtils.addConfigInfo(mContext, "MyAdd","myself");
		
		
		LoginResult loginresult = null;
		HttpUtils httputils = new HttpUtils(mContext);
		HashMap hashmap = new HashMap();
		hashmap.put("mode", "public_login");
		hashmap.put("app", "icrm:signin");
		hashmap.put("client", "android");
		hashmap.put("user_name", s);
		hashmap.put("user_key", s1);
		hashmap.put("mode", "public_login");
		hashmap.put("login_method", "dynamic");
		//hashmap.put("imei_num", s2);
		hashmap.put("imei_num", "460009240974217");//351858051064158
		//hashmap.put("device_name", s3);
		hashmap.put("device_name", "htc t328w");
		hashmap.put("client", "android");
		hashmap.put("device_screensize", s4);
		hashmap.put("os_name", "android");
		//hashmap.put("os_version", s5);
		hashmap.put("os_version", "4.0.3");
		hashmap.put("package_version", s6);
		hashmap.put("package_name", Constants.apppackage_name);
		//String s7 = httputils.executeGet("http://m.mykingdee.com/api/mauth/",hashmap);
		String s7="";
		NLog.d("debug",
				(new StringBuilder(
						"\u7528\u6237\u767B\u5F55------------\u8BF7\u6C42\u8FD4\u56DE\u7684\u6570\u636E\u662F\uFF1A"))
						.append(s7).toString());
		s7="{\"id\":9466,\"user_name\":\"zhenjing_shi\",\"if_setstaticpswd\":true,\"session_id\":\"dd885257f2340e6eda8ca3ffa862b31e\",\"login_time\":\"2013/03/13 16:12:21\",\"secret\":\"67165291\",\"user_id\":\"25490\",\"realname\":\"\u65BD\u632F\u666F\",\"expire_time\":\"2014/04/10 16:12:21\"}";
		if (!StringUtils.isEmpty(s7))
			loginresult = (LoginResult) (new Gson()).fromJson(s7, com.kingdee.signup.model.LoginResult.class);
		return loginresult;
	}

	public User getSignLoginData(String s, String s1) throws Exception {
		User user = null;
		HttpUtils httputils = new HttpUtils(mContext);
		HashMap hashmap = new HashMap();
		hashmap.put("mode", "security_check");
		hashmap.put("token", s1);
		hashmap.put("identify", s);
		hashmap.put("app", appConsumerKey);
		hashmap.put("client", "android");
		AndroidDeviceInfo.getAndroidDeviceInfo(mContext);
		hashmap.put("imei_num", AndroidDeviceInfo.getImei());
		hashmap.put("hash", getHash(s, s1));
		String s2 = httputils.executeGet("http://m.mykingdee.com/api/mauth/",
				hashmap);
		NLog.d("debug",
				(new StringBuilder(
						"\u5355\u70B9\u767B\u5F55-----------\u8BF7\u6C42\u8FD4\u56DE\u7684\u6570\u636E\u662F\uFF1A"))
						.append(s2).toString());
		//s2="\"\"";
		//s2="{\"id\":9466,\"user_name\":\"zhenjing_shi\",\"if_setstaticpswd\":true,\"session_id\":\"dd885257f2340e6eda8ca3ffa862b31e\",\"login_time\":\"2013/03/11 16:12:21\",\"secret\":\"67165291\",\"user_id\":\"25490\",\"realname\":\"\u65BD\u632F\u666F\",\"expire_time\":\"2013/04/10 16:12:21\"}";
		if (!StringUtils.isEmpty(s2))
			user = (User) (new Gson()).fromJson(s2, com.kingdee.signup.model.User.class);
		return user;
	}

	public VersionResult getVersionData() throws Exception {
		VersionResult versionresult = null;
		String s = (new HttpUtils(mContext)).executeGet(
				"http://imobile.app.mykingdee.com/install/check/feature/413",
				params);
		NLog.d("debug",
				(new StringBuilder(
						"\u68C0\u67E5\u7248\u672C\u66F4\u65B0-----------\u8BF7\u6C42\u8FD4\u56DE\u7684\u6570\u636E\u662F\uFF1A"))
						.append(s).toString());
		if (!StringUtils.isEmpty(s))
			versionresult = (VersionResult) (new Gson()).fromJson(s, com.kingdee.signup.model.VersionResult.class);
		return versionresult;
	}

	String appConsumerKey;
	String appConsumerSecret;
}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\mywork\TestSensor\libs\mykingdee.jar
	Total time: 65 ms
	Jad reported messages/errors:
Couldn't fully decompile method MD5
Couldn't resolve all exception handlers in method MD5
	Exit status: 0
	Caught exceptions:
*/